// 隐式绑定:object.fn()
// object对象会被js引擎绑定到fn函数中的this里面
function foo() {
  console.log(this);
}

// 独立函数调用 -> window
// foo()

// 案例一
var obj = {
  name: "why",
  foo: foo
}

obj.foo() // obj对象

// 案例二
var obj2 = {
  name: "why",
  eating: function () {
    // 因为是隐式绑定obj.eating() -> 所以这里实际就是obj.name
    console.log(this.name + '在吃东西');
  },
  running: function () {
    console.log(obj2.name + '在跑步');
  }
}

obj2.eating()
obj2.running()

// 案例三
var obj3 = {
  foo: function () {
    name: 'obj3',
    console.log(this.name);
    console.log(this);
  }
}

var obj4 = {
  name: 'obj4',
  bar: obj3.foo
}

obj4.bar() // 'obj4' {name: 'obj4', bar: ƒ}

// 案例四
var obj5 = {
  name: 'obj5',
  foo: foo
}

var obj6 = {
  name: 'obj6',
  obj5: obj5
}

obj6.obj5.foo() // obj5activeIndex